package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RxManageurl;
import com.ruoyi.system.service.IRxManageurlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 个性外链Controller
 *
 * @author hjf
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/hmk/manageurl")
public class RxManageurlController extends BaseController {
    @Autowired
    private IRxManageurlService rxManageurlService;

    /**
     * 查询个性外链列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurl:list')")
    @GetMapping("/list")
    public TableDataInfo list(RxManageurl rxManageurl) {
        if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
            rxManageurl.setIsHidden(1);
            rxManageurl.setManageId(SecurityUtils.getUserId());
        }
        startPage();
        List<RxManageurl> list = rxManageurlService.selectRxManageurlList(rxManageurl);
        return getDataTable(list);
    }

    /**
     * 导出个性外链列表
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurl:export')")
    //@Log(title = "个性外链", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RxManageurl rxManageurl) {
        List<RxManageurl> list = rxManageurlService.selectRxManageurlList(rxManageurl);
        ExcelUtil<RxManageurl> util = new ExcelUtil<RxManageurl>(RxManageurl.class);
        util.exportExcel(response, list, "个性外链数据");
    }

    /**
     * 获取个性外链详细信息
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurl:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rxManageurlService.selectRxManageurlById(id));
    }

    /**
     * 新增个性外链
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurl:add')")
    //@Log(title = "个性外链", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RxManageurl rxManageurl) {
        rxManageurl.setManageId(SecurityUtils.getUserId());
        rxManageurl.setIsHidden(1);
        rxManageurl.setTime(System.currentTimeMillis() / 1000);
        return toAjax(rxManageurlService.insertRxManageurl(rxManageurl));
    }

    /**
     * 修改个性外链
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurl:edit')")
    //@Log(title = "个性外链", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RxManageurl rxManageurl) {
        return toAjax(rxManageurlService.updateRxManageurl(rxManageurl));
    }

    /**
     * 删除个性外链
     */
    @PreAuthorize("@ss.hasPermi('hmk:manageurl:remove')")
    //@Log(title = "个性外链", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rxManageurlService.deleteRxManageurlByIds(ids));
    }
}
